package com.aplink.generic.pojo;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.aplink.generic.constant.type.SqlDataType;
import com.aplink.generic.util.objectrule.ValueBaseRule;

public class ObjPropInfo implements Parcelable {
    private boolean isAuto;
    private boolean isCreatedTime;
    private boolean isDeviceID;
    private boolean isFKey;
    private boolean isGroupBy;
    private boolean isImageLocalPath;
    private boolean isImageServerPath;
    private boolean isKey;
    private boolean isLatitude;
    private boolean isLongitude;
    private boolean isPassword;
    private boolean isSave = true;
    private boolean isSyncStatus;
    private boolean isToken;
    private boolean isUsername;
    private String mBackUpTable = null;
    private String mColumnName;
    private String mDataType;
    private String mDefaultValue = null;
    private String mExpress;
    private String mForeignKeyId;
    private String mForeignTable;
    private TableRelationship mRelationship;
    private String mSort;
    private String mTableName;
    private String mTableRoot;
    private String mWebserviceVariable;
    public ValueBaseRule valueBaseRule;

    public ObjPropInfo() {

    }

    public ObjPropInfo(final ObjPropInfo propInfo) {
        this.isAuto = propInfo.isAuto;
        this.isFKey = propInfo.isFKey;
        this.isKey = propInfo.isKey;
        this.mTableRoot = propInfo.mTableRoot;
        this.mDataType = propInfo.mDataType;
        this.mSort = propInfo.mSort;
        this.mForeignKeyId = propInfo.mForeignKeyId;
        this.mForeignTable = propInfo.mForeignTable;
        this.mColumnName = propInfo.mColumnName;
        this.valueBaseRule = propInfo.valueBaseRule;
        this.mWebserviceVariable = propInfo.mWebserviceVariable;
        this.isCreatedTime = propInfo.isCreatedTime;
        this.isImageServerPath = propInfo.isImageServerPath;
        this.isImageLocalPath = propInfo.isImageLocalPath;
        this.isGroupBy = propInfo.isGroupBy;
        this.mExpress = propInfo.mExpress;
        this.isSyncStatus = propInfo.isSyncStatus;
        this.mTableName = propInfo.mTableName;
        this.isSave = propInfo.isSave;
        this.mDefaultValue = propInfo.mDefaultValue;
        this.mRelationship = propInfo.getRelationship();
    }

    public String getAliasColumnName() {
        return this.mTableName + "_" + this.mColumnName;
    }

    public String getBackUpTable() {
        return this.mBackUpTable;
    }

    /**
     * This property mapping for "op_id" attribute.
     * 
     * @return
     */
    public String getColumnName() {
        return this.mColumnName;
    }

    public SqlDataType getDataType() {
        final SqlDataType dataType = SqlDataType.get(this.mDataType);
        if (dataType != null) {
            return dataType;
        }
        return null;
    }

    public String getDefaultValue() {
        return this.mDefaultValue;
    }

    public String getExpression() {
        return this.mExpress;
    }

    /**
     * This property mapping for "iskey" attribute.
     * 
     * @return
     */
    public String getFKeyID() {
        return this.mForeignKeyId;
    }

    public String getForeignFullColumnName() {
        if (TextUtils.isEmpty(this.mForeignKeyId)) {
            return this.mForeignTable + "." + this.mColumnName;
        }
        return this.mForeignTable + "." + this.mForeignKeyId;
    }

    public String getForeignKeyId() {
        return this.mForeignKeyId;
    }

    /**
     * This property mapping for "f_om_id" attribute.
     * 
     * @return
     */
    public String getForeignTable() {
        return this.mForeignTable;
    }

    public String getFullColumnName() {
        return String.format("%s.%s", this.mTableName, this.mColumnName);
    }

    public TableRelationship getRelationship() {
        return this.mRelationship;
    }

    public String getSort() {
        return this.mSort;
    }

    /**
     * This property mapping for "om_id" attribute.
     * 
     * @return
     */
    public String getTable() {
        return this.mTableName;
    }

    /**
     * This property mapping for "p_om_id" attribute.
     * 
     * @return
     */
    public String getTableRoot() {
        return this.mTableRoot;
    }

    public ValueBaseRule getValueBaseRule() {
        return this.valueBaseRule;
    }

    public String getWebserviceVariable() {
        return this.mWebserviceVariable;
    }

    public boolean isAuto() {
        return this.isAuto;
    }

    public boolean isCreatedTime() {
        return this.isCreatedTime;
    }

    public boolean isDeviceID() {
        return this.isDeviceID;
    }

    public boolean isFKey() {
        return this.isFKey;
    }

    public boolean isGroupBy() {
        return this.isGroupBy;
    }

    public boolean isImageLocalPath() {
        return this.isImageLocalPath;
    }

    public boolean isImageServerPath() {
        return this.isImageServerPath;
    }

    public boolean isKey() {
        return this.isKey;
    }

    public final boolean isLatitude() {
        return isLatitude;
    }

    public final boolean isLongitude() {
        return isLongitude;
    }

    public boolean isPassword() {
        return this.isPassword;
    }

    public boolean isSave() {
        return this.isSave;
    }

    public boolean isSort() {
        return this.mSort != null;
    }

    public boolean isSyncStatus() {
        return this.isSyncStatus;
    }

    public boolean isToken() {
        return this.isToken;
    }

    public boolean isUsername() {
        return this.isUsername;
    }

    public void setAuto(final boolean isAuto) {
        this.isAuto = isAuto;
    }

    public void setBackUpTable(final String backUpTable) {
        this.mBackUpTable = backUpTable;
    }

    public void setColumnName(final String opid) {
        this.mColumnName = opid;
    }

    public void setCreatedTime(final boolean isCreatedTime) {
        this.isCreatedTime = isCreatedTime;
    }

    public void setDataType(final String datatype) {
        this.mDataType = datatype;
    }

    public void setDefaultValue(final String defaultValue) {
        this.mDefaultValue = defaultValue;
    }

    public void setDeviceID(final boolean isDeviceID) {
        this.isDeviceID = isDeviceID;
    }

    public void setExpress(final String express) {
        this.mExpress = express;
    }

    public void setFKey(final boolean isFKey) {
        this.isFKey = isFKey;
    }

    public void setForeignKeyId(final String foreignKeyId) {
        this.mForeignKeyId = foreignKeyId;
    }

    public void setForeignObjectMapping(final String mFOm) {
        this.mForeignTable = mFOm;
    }

    public void setForeignObjectMappingId(final String foreignObjectMappingId) {
        this.mForeignTable = foreignObjectMappingId;
    }

    public void setForiegnKey(final String fkeyid) {
        this.mForeignKeyId = fkeyid;
    }

    public void setGroupBy(final boolean isGroupBy) {
        this.isGroupBy = isGroupBy;
    }

    public void setImageLocalPath(final boolean isImageLocalPath) {
        this.isImageLocalPath = isImageLocalPath;
    }

    public void setImageServerPath(final boolean isImageServerPath) {
        this.isImageServerPath = isImageServerPath;
    }

    public void setIsAuto(final boolean isAuto) {
        this.isAuto = isAuto;
    }

    public void setKey(final boolean isKey) {
        this.isKey = isKey;
    }

    public final void setLatitude(final boolean isLatitude) {
        this.isLatitude = isLatitude;
    }

    public final void setLongitude(final boolean isLongitude) {
        this.isLongitude = isLongitude;
    }

    public void setPassword(final boolean isPassword) {
        this.isPassword = isPassword;
    }

    public void setRelationship(final TableRelationship relationship) {
        this.mRelationship = relationship;
    }

    public void setSave(final boolean isIgnore) {
        this.isSave = isIgnore;
    }

    public void setSort(final String sort) {
        this.mSort = sort;
    }

    public void setSyncStatus(final boolean isSyncStatus) {
        this.isSyncStatus = isSyncStatus;
    }

    public void setTableName(final String om) {
        this.mTableName = om;
    }

    public void setTableRoot(final String tableRoot) {
        this.mTableRoot = tableRoot;
    }

    public void setToken(final boolean isToken) {
        this.isToken = isToken;
    }

    public void setUsername(final boolean isUsername) {
        this.isUsername = isUsername;
    }

    public void setValueBaseRule(final ValueBaseRule valueBaseRule) {
        this.valueBaseRule = valueBaseRule;
    }

    public void setWebserviceVariable(final String webserviceVariable) {
        this.mWebserviceVariable = webserviceVariable;
    }

    @Override
    public String toString() {
        return getFullColumnName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public ObjPropInfo(Parcel results) {

    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }

    public static final Parcelable.Creator<ObjPropInfo> CREATOR = new Parcelable.Creator<ObjPropInfo>() {

        @Override
        public ObjPropInfo createFromParcel(final Parcel source) {
            return new ObjPropInfo(source);
        }

        @Override
        public ObjPropInfo[] newArray(final int size) {
            return new ObjPropInfo[size];
        }
    };
}
